package com.niit.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.News;
import com.niit.service.NewsService;
import com.niit.service.impl.NewsServiceImpl;
import com.niit.utils.Page;
import com.niit.utils.WebKit;

@WebServlet("/ShowNewsControllerByUser")
public class ShowNewsControllerByUser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String kind = request.getParameter("kind");
		String pagenum = request.getParameter("curPage");
		NewsService ns = new NewsServiceImpl();
		Page<News> page = null;
		if(kind==null){
			page = ns.getPage(pagenum, WebKit.getServletURI(request));
		}else{
			page = ns.getPage(pagenum, WebKit.getServletURI(request), kind);
		}
		request.setAttribute("kind", kind);
		request.setAttribute("page", page);
		request.getRequestDispatcher("/jsp/user/news.jsp").forward(
				request, response);
	}

}
